
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>shell_awk · AGou's StudyNote</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="AGou">
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-anchors/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-tbfed-pagefooter/footer.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-anchor-navigation-ex/style/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-prism/prism-tomorrow.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-insert-logo/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search-pro/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-lightbox/css/lightbox.min.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-donate/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-code/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="OpenSSL、PKI搭建、算法.html" />
    
    
    <link rel="prev" href="Linux_shell.html" />
    

    <style>
    @media only screen and (max-width: 640px) {
        .book-header .hidden-mobile {
            display: none;
        }
    }
    </style>
    <script>
        window["gitbook-plugin-github-buttons"] = {"repo":"AGou-ops/myStudyNote","types":["star","watch","fork"],"size":"small"};
    </script>

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    
    
        
        <li>
            <a href="http://agou-ops.github.io" target="_blank" class="custom-link">◆点击进入我的个人博客</a>
        </li>
    
    

    
    <li class="divider"></li>
    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                        <b>1.1.</b>
                    
                    关于我
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../Program_lang/">
            
                <a href="../Program_lang/">
            
                    
                        <b>1.2.</b>
                    
                    编程语言
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../Program_lang/Python.html">
            
                <a href="../Program_lang/Python.html">
            
                    
                        <b>1.2.1.</b>
                    
                    Python
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../Program_lang/Java.html">
            
                <a href="../Program_lang/Java.html">
            
                    
                        <b>1.2.2.</b>
                    
                    Java
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="../Program_lang/Splash_Lua.html">
            
                <a href="../Program_lang/Splash_Lua.html">
            
                    
                        <b>1.2.3.</b>
                    
                    Splash_Lua
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../Database/">
            
                <a href="../Database/">
            
                    
                        <b>1.3.</b>
                    
                    数据库
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../Database/Mysql、MariaDB/README.md">
            
                <span>
            
                    
                        <b>1.3.1.</b>
                    
                    Mysql/MariaDB
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1.1" data-path="../Database/Mysql、MariaDB/MySQL、MariaDB基础.html">
            
                <a href="../Database/Mysql、MariaDB/MySQL、MariaDB基础.html">
            
                    
                        <b>1.3.1.1.</b>
                    
                    MySQL/MariaDB基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.1.2" data-path="../Database/Mysql、MariaDB/php-mysql.html">
            
                <a href="../Database/Mysql、MariaDB/php-mysql.html">
            
                    
                        <b>1.3.1.2.</b>
                    
                    php-mysql
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../Database/MongoDB.html">
            
                <a href="../Database/MongoDB.html">
            
                    
                        <b>1.3.2.</b>
                    
                    MongoDB
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../Database/Redis.html">
            
                <a href="../Database/Redis.html">
            
                    
                        <b>1.3.3.</b>
                    
                    Redis
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="./">
            
                <a href="./">
            
                    
                        <b>1.4.</b>
                    
                    Linux
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="Linux基础.html">
            
                <a href="Linux基础.html">
            
                    
                        <b>1.4.1.</b>
                    
                    Linux基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="Linux启动流程、内核、grub、模块、内核的编译、anaconda自动化.html">
            
                <a href="Linux启动流程、内核、grub、模块、内核的编译、anaconda自动化.html">
            
                    
                        <b>1.4.2.</b>
                    
                    Linux启动流程、内核、grub、模块等
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="Linux服务器.html">
            
                <a href="Linux服务器.html">
            
                    
                        <b>1.4.3.</b>
                    
                    Linux服务器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="Linux状态信息.html">
            
                <a href="Linux状态信息.html">
            
                    
                        <b>1.4.4.</b>
                    
                    Linux状态信息
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="Linux网络客户端工具.html">
            
                <a href="Linux网络客户端工具.html">
            
                    
                        <b>1.4.5.</b>
                    
                    Linux网络客户端工具
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.6" data-path="Linux网络配置.html">
            
                <a href="Linux网络配置.html">
            
                    
                        <b>1.4.6.</b>
                    
                    Linux网络配置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7" data-path="Linux配置文件.md">
            
                <span>
            
                    
                        <b>1.4.7.</b>
                    
                    Linux配置文件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.8" data-path="Linux时间服务器.html">
            
                <a href="Linux时间服务器.html">
            
                    
                        <b>1.4.8.</b>
                    
                    Linux时间服务器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.9" data-path="Linux日志管理系统.html">
            
                <a href="Linux日志管理系统.html">
            
                    
                        <b>1.4.9.</b>
                    
                    Linux日志管理系统
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.10" data-path="sudo详解.html">
            
                <a href="sudo详解.html">
            
                    
                        <b>1.4.10.</b>
                    
                    sudo详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.11" data-path="SElinux.html">
            
                <a href="SElinux.html">
            
                    
                        <b>1.4.11.</b>
                    
                    SELinux
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.12" data-path="iptables.html">
            
                <a href="iptables.html">
            
                    
                        <b>1.4.12.</b>
                    
                    iptables
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.13" data-path="Linux_shell.html">
            
                <a href="Linux_shell.html">
            
                    
                        <b>1.4.13.</b>
                    
                    Linux Shell
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.4.14" data-path="shell_awk.html">
            
                <a href="shell_awk.html">
            
                    
                        <b>1.4.14.</b>
                    
                    shell_awk
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.15" data-path="OpenSSL、PKI搭建、算法.html">
            
                <a href="OpenSSL、PKI搭建、算法.html">
            
                    
                        <b>1.4.15.</b>
                    
                    OpenSSL、PKI搭建
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.16" data-path="DNS服务器.html">
            
                <a href="DNS服务器.html">
            
                    
                        <b>1.4.16.</b>
                    
                    DNS服务器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.17" data-path="Frp内网穿透.html">
            
                <a href="Frp内网穿透.html">
            
                    
                        <b>1.4.17.</b>
                    
                    Frp内网穿透
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.18" data-path="Linux其他.md">
            
                <span>
            
                    
                        <b>1.4.18.</b>
                    
                    Linux其他
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../Linux_FileSystem/">
            
                <a href="../Linux_FileSystem/">
            
                    
                        <b>1.5.</b>
                    
                    Linux文件系统
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../Linux_FileSystem/FTP.html">
            
                <a href="../Linux_FileSystem/FTP.html">
            
                    
                        <b>1.5.1.</b>
                    
                    FTP
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../Linux_FileSystem/SAMBA.html">
            
                <a href="../Linux_FileSystem/SAMBA.html">
            
                    
                        <b>1.5.2.</b>
                    
                    SAMBA
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../Linux_Tools/">
            
                <a href="../Linux_Tools/">
            
                    
                        <b>1.6.</b>
                    
                    Linux工具
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../Linux_Tools/fzf工具.html">
            
                <a href="../Linux_Tools/fzf工具.html">
            
                    
                        <b>1.6.1.</b>
                    
                    fzf工具
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="../Linux_Tools/工具集合.html">
            
                <a href="../Linux_Tools/工具集合.html">
            
                    
                        <b>1.6.2.</b>
                    
                    Linux工具集合
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../WEB_Server/">
            
                <a href="../WEB_Server/">
            
                    
                        <b>1.7.</b>
                    
                    网站服务器
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../WEB_Server/HTML基础.html">
            
                <a href="../WEB_Server/HTML基础.html">
            
                    
                        <b>1.7.1.</b>
                    
                    HTML基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="../WEB_Server/WEB基础.html">
            
                <a href="../WEB_Server/WEB基础.html">
            
                    
                        <b>1.7.2.</b>
                    
                    WEB基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3" data-path="../WEB_Server/httpd.html">
            
                <a href="../WEB_Server/httpd.html">
            
                    
                        <b>1.7.3.</b>
                    
                    httpd/Apache
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.4" data-path="../WEB_Server/httpd.conf文件详解.html">
            
                <a href="../WEB_Server/httpd.conf文件详解.html">
            
                    
                        <b>1.7.4.</b>
                    
                    httpd.conf文件详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.5" data-path="../WEB_Server/Nginx.html">
            
                <a href="../WEB_Server/Nginx.html">
            
                    
                        <b>1.7.5.</b>
                    
                    Nginx
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.6" data-path="../WEB_Server/HTTP状态码-详情.html">
            
                <a href="../WEB_Server/HTTP状态码-详情.html">
            
                    
                        <b>1.7.6.</b>
                    
                    HTTP状态码-详情
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="../Common_Framework/">
            
                <a href="../Common_Framework/">
            
                    
                        <b>1.8.</b>
                    
                    常用框架
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1" data-path="../Common_Framework/LNMP.html">
            
                <a href="../Common_Framework/LNMP.html">
            
                    
                        <b>1.8.1.</b>
                    
                    LNMP
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.2" data-path="../Common_Framework/LAMP.html">
            
                <a href="../Common_Framework/LAMP.html">
            
                    
                        <b>1.8.2.</b>
                    
                    LAMP
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="../Docker&K8s/">
            
                <a href="../Docker&K8s/">
            
                    
                        <b>1.9.</b>
                    
                    容器及容器编排
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.1" data-path="../Docker&K8s/Docker/Docker.html">
            
                <a href="../Docker&K8s/Docker/Docker.html">
            
                    
                        <b>1.9.1.</b>
                    
                    Docker
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.1.1" data-path="../Docker&K8s/Docker/Docker.html">
            
                <a href="../Docker&K8s/Docker/Docker.html">
            
                    
                        <b>1.9.1.1.</b>
                    
                    Docker
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9.2" data-path="../Docker&K8s/K8s/">
            
                <a href="../Docker&K8s/K8s/">
            
                    
                        <b>1.9.2.</b>
                    
                    K8s
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.2.1" data-path="../Docker&K8s/K8s/K8s基础知识.html">
            
                <a href="../Docker&K8s/K8s/K8s基础知识.html">
            
                    
                        <b>1.9.2.1.</b>
                    
                    K8s基础知识
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.2.2" data-path="../Docker&K8s/K8s/K8s安装与部署.html">
            
                <a href="../Docker&K8s/K8s/K8s安装与部署.html">
            
                    
                        <b>1.9.2.2.</b>
                    
                    K8s安装与部署
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="../Git/">
            
                <a href="../Git/">
            
                    
                        <b>1.10.</b>
                    
                    Git
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.10.1" data-path="../Git/Git基础.html">
            
                <a href="../Git/Git基础.html">
            
                    
                        <b>1.10.1.</b>
                    
                    Git基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.2" data-path="../Git/GitLab服务器.html">
            
                <a href="../Git/GitLab服务器.html">
            
                    
                        <b>1.10.2.</b>
                    
                    GitLab服务器
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="../Windows/">
            
                <a href="../Windows/">
            
                    
                        <b>1.11.</b>
                    
                    Windows系统
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.11.1" data-path="../Windows/cmd命令.html">
            
                <a href="../Windows/cmd命令.html">
            
                    
                        <b>1.11.1.</b>
                    
                    cmd命令
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="../Vim.html">
            
                <a href="../Vim.html">
            
                    
                        <b>1.12.</b>
                    
                    Vim
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="../i3WM快捷键.html">
            
                <a href="../i3WM快捷键.html">
            
                    
                        <b>1.13.</b>
                    
                    i3WM快捷键
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14" data-path="../ADB命令.html">
            
                <a href="../ADB命令.html">
            
                    
                        <b>1.14.</b>
                    
                    ADB命令
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15" data-path="../Tmux.html">
            
                <a href="../Tmux.html">
            
                    
                        <b>1.15.</b>
                    
                    Tmux
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.16" data-path="../Kindle.html">
            
                <a href="../Kindle.html">
            
                    
                        <b>1.16.</b>
                    
                    Kindle越狱指南
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17" data-path="../Other/">
            
                <a href="../Other/">
            
                    
                        <b>1.17.</b>
                    
                    Other
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.17.1" data-path="../Other/pandoc.html">
            
                <a href="../Other/pandoc.html">
            
                    
                        <b>1.17.1.</b>
                    
                    pandoc
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17.2" data-path="../Other/jupyter&reveal.js.html">
            
                <a href="../Other/jupyter&reveal.js.html">
            
                    
                        <b>1.17.2.</b>
                    
                    jupyter & reveal.js
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17.3" data-path="../Other/json.html">
            
                <a href="../Other/json.html">
            
                    
                        <b>1.17.3.</b>
                    
                    json
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17.4" data-path="../Other/Reveal_js.html">
            
                <a href="../Other/Reveal_js.html">
            
                    
                        <b>1.17.4.</b>
                    
                    Reveal_js
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >shell_awk</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <div id="anchor-navigation-ex-navbar"><i class="fa fa-anchor"></i><ul><li><a href="#&#x57FA;&#x672C;&#x683C;&#x5F0F;">1. &#x57FA;&#x672C;&#x683C;&#x5F0F;</a></li><li><a href="#&#x6A21;&#x5F0F;&#x5339;&#x914D;">2. &#x6A21;&#x5F0F;&#x5339;&#x914D;</a></li><li><a href="#&#x53D8;&#x91CF;">3. &#x53D8;&#x91CF;</a></li><li><a href="#array">4. array</a></li><li><a href="#&#x683C;&#x5F0F;&#x5316;&#x8F93;&#x51FA;printf">5. &#x683C;&#x5F0F;&#x5316;&#x8F93;&#x51FA;printf</a></li><li><a href="#&#x51FD;&#x6570;">6. &#x51FD;&#x6570;</a></li><li><a href="#&#x6761;&#x4EF6;">7. &#x6761;&#x4EF6;</a></li><li><a href="#if&#x8BED;&#x53E5;">8. if&#x8BED;&#x53E5;</a></li><li><a href="#&#x9009;&#x9879;">9. &#x9009;&#x9879;</a></li><li><a href="#&#x5176;&#x4ED6;">10. &#x5176;&#x4ED6;</a></li><li><a href="#&#x4F8B;&#x5B50;">11. &#x4F8B;&#x5B50;</a></li><li><a href="#&#x53C2;&#x8003;&#x94FE;&#x63A5;">12. &#x53C2;&#x8003;&#x94FE;&#x63A5;</a></li></ul></div><a href="#&#x57FA;&#x672C;&#x683C;&#x5F0F;" id="anchorNavigationExGoTop"><i class="fa fa-arrow-up"></i></a><blockquote>
<p><strong>This is shell_awk StudyNote.</strong></p>
</blockquote>
<h1 id="&#x57FA;&#x672C;&#x683C;&#x5F0F;"><a name="&#x57FA;&#x672C;&#x683C;&#x5F0F;" class="anchor-navigation-ex-anchor" href="#&#x57FA;&#x672C;&#x683C;&#x5F0F;"><i class="fa fa-link" aria-hidden="true"></i></a>1. &#x57FA;&#x672C;&#x683C;&#x5F0F;</h1>
<ul>
<li><pre class="language-"><code class="lang-bash"><span class="token function">awk</span> &#x52A8;&#x4F5C; &#x6587;&#x4EF6;&#x540D;
<span class="token function">awk</span> <span class="token string">&apos;BEGIN{}/pattern(REGEX)/{commmand}END{}&apos;</span>
<span class="token comment"># &#x793A;&#x4F8B;1</span>
<span class="token function">awk</span> <span class="token string">&apos;{print <span class="token variable">$0</span>}&apos;</span> <span class="token builtin class-name">test</span>  <span class="token comment"># $0&#x4EE3;&#x8868;&#x5F53;&#x524D;&#x884C;&#xFF0C;&#x56E0;&#x6B64;&#x4E0A;&#x9762;&#x547D;&#x4EE4;&#x7684;&#x6267;&#x884C;&#x7ED3;&#x679C;&#xFF0C;&#x5C31;&#x662F;&#x628A;&#x6BCF;&#x4E00;&#x884C;&#x539F;&#x6837;&#x6253;&#x5370;&#x51FA;&#x6765;</span>
<span class="token comment"># &#x793A;&#x4F8B;2</span>
<span class="token builtin class-name">echo</span> <span class="token string">&apos;this is a test&apos;</span> <span class="token operator">|</span> <span class="token function">awk</span> <span class="token string">&apos;{print <span class="token variable">$0</span>}&apos;</span>  <span class="token comment"># &#x4F7F;&#x7528;&#x6807;&#x51C6;&#x8F93;&#x51FA;</span>
<span class="token comment"># &#x793A;&#x4F8B;3</span>
<span class="token function">awk</span> <span class="token string">&apos;BEGIN{NF=&quot;:&quot;}{print <span class="token variable">$2</span>}&apos;</span> filename    <span class="token comment"># &#x4F7F;&#x7528;BEGIN&#x5BF9;&#x6587;&#x4EF6;&#x8FDB;&#x884C;&#x9884;&#x5904;&#x7406;</span>
</code></pre>
</li>
<li><pre class="language-"><code class="lang-bash"><span class="token variable">$1</span>&#x3001;<span class="token variable">$2</span>&#x3001;<span class="token variable">$3</span>&#x4EE3;&#x8868;&#x7B2C;&#x4E00;&#x4E2A;&#x5B57;&#x6BB5;&#x3001;&#x7B2C;&#x4E8C;&#x4E2A;&#x5B57;&#x6BB5;&#x3001;&#x7B2C;&#x4E09;&#x4E2A;&#x5B57;&#x6BB5;&#x7B49;&#x7B49;&#xFF0C;&#x5176;&#x9ED8;&#x8BA4;&#x5206;&#x9694;&#x7B26;&#x4E3A;&#x7A7A;&#x683C;&#x6216;&#x8005;&#x662F;TAB
<span class="token function">awk</span> -F <span class="token string">&apos;:&apos;</span> <span class="token string">&apos;{ print <span class="token variable">$1</span>,<span class="token variable">$2</span> }&apos;</span>  <span class="token comment"># &#x4F7F;&#x7528;-F &#x9009;&#x9879;&#x53EF;&#x4EE5;&#x81EA;&#x5B9A;&#x4E49;&#x5206;&#x9694;&#x7B26;</span>
<span class="token comment"># &#x591A;&#x4E2A;&#x5B57;&#x6BB5;&#x4E4B;&#x95F4;&#x4F7F;&#x7528;&#x9017;&#x53F7;&#x5206;&#x5F00;&#x6216;&#x8005;&#x7A7A;&#x683C;&#x5206;&#x5F00;&#xFF0C;&#x6548;&#x679C;&#x4E0D;&#x4E00;&#x6837;&#x3002;</span>
</code></pre>
<h1 id="&#x6A21;&#x5F0F;&#x5339;&#x914D;"><a name="&#x6A21;&#x5F0F;&#x5339;&#x914D;" class="anchor-navigation-ex-anchor" href="#&#x6A21;&#x5F0F;&#x5339;&#x914D;"><i class="fa fa-link" aria-hidden="true"></i></a>2. &#x6A21;&#x5F0F;&#x5339;&#x914D;</h1>
</li>
<li><pre class="language-"><code class="lang-bash"><span class="token comment"># &#x4E24;&#x79CD;&#x6A21;&#x5F0F;&#x5339;&#x914D;&#x65B9;&#x5F0F;</span>
<span class="token comment"># &#x7B2C;&#x4E00;&#x79CD;&#xFF0C;&#x4F7F;&#x7528;&#x6B63;&#x5219;&#x8868;&#x8FBE;&#x5F0F;</span>
<span class="token function">awk</span> <span class="token string">&apos;/[REGEX]/{print <span class="token variable">$0</span>}&apos;</span> <span class="token builtin class-name">test</span>
<span class="token comment"># &#x7B2C;&#x4E8C;&#x79CD;&#xFF0C;&#x4F7F;&#x7528;&#x5173;&#x7CFB;&#x8FD0;&#x7B97;&#x7B26;&#xFF0C;&gt;,&lt;,&lt;=,&gt;=,==,~(&#x5339;&#x914D;regex),!~(&#x4E0D;&#x5339;&#x914D;regex&#x7684;&#x884C;&#x4FE1;&#x606F;)</span>
<span class="token comment"># &#x903B;&#x8F91;&#x8FD0;&#x7B97;&#x7B26;&#xFF0C;&#x4E0E;&#x6216;&#x975E;&#xFF0C;&amp;&amp;,||,!</span>
<span class="token function">awk</span> <span class="token string">&apos;<span class="token variable">$3</span>&gt;50{print <span class="token variable">$0</span>}&apos;</span> <span class="token builtin class-name">test</span>  <span class="token comment"># &#x8F93;&#x51FA;&#x7B2C;&#x4E09;&#x4E2A;&#x5B57;&#x6BB5;&#x957F;&#x5EA6;&#x5927;&#x4E8E;50&#x7684;&#x6240;&#x6709;&#x884C;&#x4FE1;&#x606F;</span>
<span class="token function">awk</span> <span class="token string">&apos;<span class="token variable">$3</span>==&quot;test&quot;{print <span class="token variable">$0</span>}&apos;</span> <span class="token builtin class-name">test</span>  <span class="token comment"># &#x8F93;&#x51FA;&#x7B2C;&#x4E09;&#x4E2A;&#x5B57;&#x6BB5;&#x548C;test&#x76F8;&#x540C;&#x7684;&#x6240;&#x6709;&#x884C;&#x4FE1;&#x606F;</span>
<span class="token function">awk</span> <span class="token string">&apos;<span class="token variable">$3</span>~/[0-9]{3}/{print <span class="token variable">$0</span>}&apos;</span> <span class="token builtin class-name">test</span> <span class="token comment"># &#x8F93;&#x51FA;&#x7B2C;&#x4E09;&#x4E2A;&#x5B57;&#x6BB5;&#x7B26;&#x5408;&#x6B63;&#x5219;&#x7684;&#x6240;&#x6709;&#x884C;&#x4FE1;&#x606F;</span>
<span class="token function">awk</span> <span class="token string">&apos;<span class="token variable">$3</span>&lt;29&amp;&amp;<span class="token variable">$2</span>&gt;213{print <span class="token variable">$0</span>}&apos;</span> <span class="token builtin class-name">test</span>
</code></pre>
</li>
</ul>
<h1 id="&#x53D8;&#x91CF;"><a name="&#x53D8;&#x91CF;" class="anchor-navigation-ex-anchor" href="#&#x53D8;&#x91CF;"><i class="fa fa-link" aria-hidden="true"></i></a>3. &#x53D8;&#x91CF;</h1>
<ul>
<li><p><code>$ + &#x6570;&#x5B57;</code>&#x8868;&#x793A;&#x67D0;&#x4E2A;&#x5B57;&#x6BB5;&#xFF0C;&#x53D8;&#x91CF;<code>NF</code>&#x8868;&#x793A;&#x5F53;&#x524D;&#x884C;&#x6709;&#x591A;&#x5C11;&#x4E2A;&#x5B57;&#x6BB5;&#xFF0C;&#x56E0;&#x6B64;<code>$NF</code>(Number Field)&#x5C31;&#x4EE3;&#x8868;&#x6700;&#x540E;&#x4E00;&#x4E2A;&#x5B57;&#x6BB5;</p>
<ul>
<li><pre class="language-"><code class="lang-bash"><span class="token function">awk</span> <span class="token string">&apos;{print NF, <span class="token variable"><span class="token variable">$(</span>NF-1<span class="token variable">)</span></span>}&apos;</span> <span class="token builtin class-name">test</span>
<span class="token number">3</span> java
<span class="token number">3</span> python
<span class="token number">4</span> feiya
</code></pre>
</li>
</ul>
</li>
<li><p>&#x53D8;&#x91CF;<code>NR</code>(Number row)&#x8868;&#x793A;&#x5F53;&#x524D;&#x5904;&#x7406;&#x7684;&#x662F;&#x7B2C;&#x51E0;&#x884C;&#xFF0C;&#x7C7B;&#x4F3C;&#x8FD8;&#x6709;<code>FNR</code></p>
<ul>
<li><pre class="language-"><code class="lang-bash"><span class="token function">awk</span> -F/FS <span class="token string">&apos;:&apos;</span> <span class="token string">&apos;{print NR &quot;) &quot; <span class="token variable">$1</span>}&apos;</span> <span class="token builtin class-name">test</span>  <span class="token comment"># &#x82E5;&#x8981;&#x5C06;&#x5B57;&#x7B26;&#x539F;&#x6837;&#x8F93;&#x51FA;&#x9700;&#x8981;&#x52A0;&#x5165;&#x53CC;&#x5F15;&#x53F7;</span>
<span class="token number">1</span><span class="token punctuation">)</span> 001 hello ja&#x63D0;&#x4F9B;&#x4E86;&#x4E00;&#x4E9B;&#x5185;&#x7F6E;&#x51FD;&#x6570;&#xFF0C;&#x65B9;&#x4FBF;&#x5BF9;&#x539F;&#x59CB;&#x6570;&#x636E;&#x7684;&#x5904;&#x7406;&#x3002;
<span class="token number">2</span><span class="token punctuation">)</span> 004 hello suo feiya
</code></pre>
</li>
</ul>
</li>
<li><p>&#x5176;&#x4ED6;&#x5185;&#x7F6E;&#x53D8;&#x91CF;</p>
<ul>
<li><pre class="language-"><code class="lang-bash">FNR<span class="token punctuation">(</span>file number field<span class="token punctuation">)</span>: &#x5355;&#x72EC;&#x8F93;&#x51FA;&#x6BCF;&#x4E2A;&#x6587;&#x4EF6;&#x7684;&#x884C;&#x53F7;
FILENAME&#xFF1A;&#x5F53;&#x524D;&#x6587;&#x4EF6;&#x540D;
    <span class="token function">awk</span> <span class="token string">&apos;{print FILENAME}&apos;</span>
FS<span class="token punctuation">(</span>field separator<span class="token punctuation">)</span>&#xFF1A;&#x5B57;&#x6BB5;&#x5206;&#x9694;&#x7B26;&#xFF0C;&#x9ED8;&#x8BA4;&#x662F;&#x7A7A;&#x683C;&#x548C;&#x5236;&#x8868;&#x7B26;&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x662F;&#x7A7A;&#x683C;&#x548C;tab&#x7684;&#x6DF7;&#x5408;&#x3002;
RS<span class="token punctuation">(</span>row sepatator<span class="token punctuation">)</span>&#xFF1A;&#x884C;&#x5206;&#x9694;&#x7B26;&#xFF0C;&#x7528;&#x4E8E;&#x5206;&#x5272;&#x6BCF;&#x4E00;&#x884C;&#xFF0C;&#x9ED8;&#x8BA4;&#x662F;&#x6362;&#x884C;&#x7B26;&#x3002;
    <span class="token function">awk</span> <span class="token string">&apos;BEGIN{RS=&quot;---&quot;}{print <span class="token variable">$0</span>}&apos;</span> FILENAME
OFS<span class="token punctuation">(</span>output FS<span class="token punctuation">)</span>&#xFF1A;&#x8F93;&#x51FA;&#x5B57;&#x6BB5;&#x7684;&#x5206;&#x9694;&#x7B26;&#xFF0C;&#x7528;&#x4E8E;&#x6253;&#x5370;&#x65F6;&#x5206;&#x9694;&#x5B57;&#x6BB5;&#xFF0C;&#x9ED8;&#x8BA4;&#x4E3A;&#x7A7A;&#x683C;&#x3002;
ORS<span class="token punctuation">(</span>output RS<span class="token punctuation">)</span>&#xFF1A;&#x8F93;&#x51FA;&#x8BB0;&#x5F55;&#x7684;&#x5206;&#x9694;&#x7B26;&#xFF0C;&#x7528;&#x4E8E;&#x6253;&#x5370;&#x65F6;&#x5206;&#x9694;&#x8BB0;&#x5F55;&#xFF0C;&#x9ED8;&#x8BA4;&#x4E3A;&#x6362;&#x884C;&#x7B26;&#x3002;
OFMT&#xFF1A;&#x6570;&#x5B57;&#x8F93;&#x51FA;&#x7684;&#x683C;&#x5F0F;&#xFF0C;&#x9ED8;&#x8BA4;&#x4E3A;&#xFF05;.6g&#x3002;
ARGC:&#x547D;&#x4EE4;&#x884C;&#x53C2;&#x6570;&#x4E2A;&#x6570;
ARGV:&#x547D;&#x4EE4;&#x884C;&#x53C2;&#x6570;&#x6570;&#x7EC4;
</code></pre>
</li>
</ul>
</li>
</ul>
<h1 id="array"><a name="array" class="anchor-navigation-ex-anchor" href="#array"><i class="fa fa-link" aria-hidden="true"></i></a>4. array</h1>
<ul>
<li><p><code>awk</code> &#x4E2D;&#x7684;&#x6570;&#x7EC4;&#x4E0E;<code>shell</code>&#x4E2D;&#x7684;&#x6570;&#x7EC4;&#x6709;&#x4E9B;&#x8BB8;&#x4E0D;&#x540C;</p>
</li>
<li><p>awk&#x6570;&#x7EC4;&#x5199;&#x6CD5;</p>
<ul>
<li><pre class="language-"><code class="lang-bash"><span class="token comment"># awk&#x4E2D;&#x7684;&#x6570;&#x7EC4;&#x5143;&#x7D20;&#x53EF;&#x4EE5;&#x4E0D;&#x8FDE;&#x7EED;</span>
<span class="token function">awk</span> <span class="token string">&apos;BEGIN{array[0]=&quot;suofeiya&quot;;array[1]=&quot;hello&quot;;array[2]=&quot;world&quot;;print array[0]}&apos;</span>
<span class="token comment"># awk&#x6570;&#x7EC4;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x952E;&#x503C;&#x5BF9;</span>
<span class="token function">awk</span> <span class="token string">&apos;BEGIN{array[&quot;hello&quot;]=&quot;suofeiya&quot;;print array[&quot;hello&quot;]}&apos;</span>
</code></pre>
</li>
</ul>
</li>
<li><pre class="language-"><code class="lang-bash"><span class="token comment"># &#x904D;&#x5386;&#x6570;&#x7EC4;</span>
for<span class="token punctuation">(</span>a <span class="token keyword">in</span> array<span class="token punctuation">)</span>
    print array<span class="token punctuation">[</span>a<span class="token punctuation">]</span>
</code></pre>
</li>
<li><p>&#x53EF;&#x4EE5;&#x4F7F;&#x7528;<code>if index in array[index]</code>&#x6765;&#x5224;&#x65AD;&#x662F;&#x5426;&#x5B58;&#x5728;&#x76F8;&#x5E94;&#x7684;&#x5143;&#x7D20;</p>
</li>
</ul>
<h1 id="&#x683C;&#x5F0F;&#x5316;&#x8F93;&#x51FA;printf"><a name="&#x683C;&#x5F0F;&#x5316;&#x8F93;&#x51FA;printf" class="anchor-navigation-ex-anchor" href="#&#x683C;&#x5F0F;&#x5316;&#x8F93;&#x51FA;printf"><i class="fa fa-link" aria-hidden="true"></i></a>5. &#x683C;&#x5F0F;&#x5316;&#x8F93;&#x51FA;printf</h1>
<ul>
<li><pre class="language-"><code class="lang-bash"><span class="token comment"># &#x683C;&#x5F0F;&#x7B26;</span>
%f &#x6D6E;&#x70B9;&#x6570;
%x <span class="token number">16</span>&#x8FDB;&#x5236;&#x6570;&#x5B57;
%o <span class="token number">8</span>&#x8FDB;&#x5236;&#x6570;
%e &#x4F7F;&#x7528;&#x79D1;&#x5B66;&#x8BA1;&#x6570;&#x6CD5;
%c &#x6253;&#x5370;&#x5355;&#x4E2A;&#x5B57;&#x7B26;&#x7684;ASCII&#x7801;
<span class="token comment"># &#x5DE6;&#x53F3;&#x5BF9;&#x9F50;</span>
-  &#x5DE6;&#x5BF9;&#x9F50;
+  &#x53F3;&#x5BF9;&#x9F50;
<span class="token punctuation">\</span># &#x663E;&#x793A;&#x5728;&#x516B;&#x8FDB;&#x5236;&#x524D;&#x9762;&#x52A0;&#x4E0A;0&#xFF0C;&#x5341;&#x516D;&#x8FDB;&#x5236;&#x524D;&#x9762;&#x52A0;&#x4E0A;0x
</code></pre>
</li>
<li><pre class="language-"><code class="lang-bash"><span class="token comment"># &#x57FA;&#x672C;&#x4F7F;&#x7528;&#x65B9;&#x6CD5;</span>
<span class="token function">awk</span> <span class="token string">&apos;{printf &quot;%-10s  %-20s<span class="token entity" title="\n">\n</span>&quot;,<span class="token variable">$1</span>,<span class="token variable">$3</span>}&apos;</span> <span class="token builtin class-name">test</span>
<span class="token function">awk</span> <span class="token string">&apos;{printf &quot;%#x&quot;,<span class="token variable">$1</span>}&apos;</span> <span class="token builtin class-name">test</span>
</code></pre>
</li>
</ul>
<h1 id="&#x51FD;&#x6570;"><a name="&#x51FD;&#x6570;" class="anchor-navigation-ex-anchor" href="#&#x51FD;&#x6570;"><i class="fa fa-link" aria-hidden="true"></i></a>6. &#x51FD;&#x6570;</h1>
<ul>
<li><p>&#x7B80;&#x5355;&#x4E3E;&#x4F8B;</p>
<ul>
<li><pre class="language-"><code class="lang-bash"><span class="token comment"># &#x4F7F;&#x7528;awk&#x5185;&#x7F6E;&#x51FD;&#x6570;toupper()&#x5C06;&#x5185;&#x5BB9;&#x8F6C;&#x6362;&#x4E3A;&#x5927;&#x5199;</span>
<span class="token function">awk</span> <span class="token string">&apos;{print toupper(<span class="token variable">$0</span> }&apos;</span> <span class="token builtin class-name">test</span>
</code></pre>
</li>
</ul>
</li>
<li><p>&#x5176;&#x4ED6;&#x5185;&#x7F6E;&#x51FD;&#x6570;</p>
<ul>
<li><pre class="language-"><code class="lang-bash">tolower<span class="token punctuation">(</span><span class="token punctuation">)</span>&#xFF1A;&#x5B57;&#x7B26;&#x8F6C;&#x4E3A;&#x5C0F;&#x5199;
length<span class="token punctuation">(</span><span class="token punctuation">)</span>&#xFF1A;&#x8FD4;&#x56DE;&#x5B57;&#x7B26;&#x4E32;&#x957F;&#x5EA6;
substr<span class="token punctuation">(</span><span class="token punctuation">)</span>&#xFF1A;&#x8FD4;&#x56DE;&#x5B50;&#x5B57;&#x7B26;&#x4E32;
sin<span class="token punctuation">(</span><span class="token punctuation">)</span>&#xFF1A;&#x6B63;&#x5F26;
cos<span class="token punctuation">(</span><span class="token punctuation">)</span>&#xFF1A;&#x4F59;&#x5F26;
sqrt<span class="token punctuation">(</span><span class="token punctuation">)</span>&#xFF1A;&#x5E73;&#x65B9;&#x6839;
rand<span class="token punctuation">(</span><span class="token punctuation">)</span>&#xFF1A;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;0-1&#x4E4B;&#x95F4;&#x7684;&#x968F;&#x673A;&#x6570;
</code></pre>
</li>
<li><p>&#x5B8C;&#x6574;&#x51FD;&#x6570;&#x624B;&#x518C;&#xFF1A;<a href="https://www.gnu.org/software/gawk/manual/html_node/Built_002din.html#Built_002din" target="_blank">https://www.gnu.org/software/gawk/manual/html_node/Built_002din.html#Built_002din</a></p>
</li>
</ul>
</li>
</ul>
<h1 id="&#x6761;&#x4EF6;"><a name="&#x6761;&#x4EF6;" class="anchor-navigation-ex-anchor" href="#&#x6761;&#x4EF6;"><i class="fa fa-link" aria-hidden="true"></i></a>7. &#x6761;&#x4EF6;</h1>
<ul>
<li><p>&#x683C;&#x5F0F;&#xFF1A;<code>awk &apos;&#x6761;&#x4EF6; &#x52A8;&#x4F5C;&apos; &#x6587;&#x4EF6;&#x540D;</code></p>
<ul>
<li><pre class="language-"><code class="lang-bash"><span class="token comment"># print&#x547D;&#x4EE4;&#x524D;&#x9762;&#x662F;&#x4E00;&#x4E2A;&#x6B63;&#x5219;&#x8868;&#x8FBE;&#x5F0F;&#xFF0C;&#x53EA;&#x8F93;&#x51FA;&#x5305;&#x542B;awk&#x7684;&#x884C;</span>
<span class="token function">awk</span> <span class="token string">&apos;/awk/ {print <span class="token variable">$0</span>}&apos;</span> <span class="token builtin class-name">test</span>
</code></pre>
</li>
<li><pre class="language-"><code class="lang-shell"><span class="token comment"># &#x53EA;&#x8F93;&#x51FA;&#x5947;&#x6570;&#x884C;&#x5185;&#x5BB9;</span>
<span class="token function">awk</span> <span class="token string">&apos;NR % 2 == 1 {print <span class="token variable">$0</span>}&apos;</span> <span class="token builtin class-name">test</span>
<span class="token comment"># &#x8F93;&#x51FA;&#x7B2C;&#x4E8C;&#x884C;&#x4EE5;&#x540E;&#x7684;&#x5185;&#x5BB9;</span>
<span class="token function">awk</span> <span class="token string">&apos;NR &gt; 2 {print <span class="token variable">$0</span>}&apos;</span> <span class="token builtin class-name">test</span>
</code></pre>
</li>
</ul>
</li>
</ul>
<h1 id="if&#x8BED;&#x53E5;"><a name="if&#x8BED;&#x53E5;" class="anchor-navigation-ex-anchor" href="#if&#x8BED;&#x53E5;"><i class="fa fa-link" aria-hidden="true"></i></a>8. if&#x8BED;&#x53E5;</h1>
<ul>
<li><pre class="language-"><code class="lang-bash"><span class="token function">awk</span> <span class="token string">&apos;{if (<span class="token variable">$1</span> &gt; &quot;m&quot;) print <span class="token variable">$1</span>}&apos;</span> <span class="token builtin class-name">test</span>
<span class="token function">awk</span> <span class="token string">&apos;{if (<span class="token variable">$1</span> &gt; &quot;m&quot;) print <span class="token variable">$1</span>; else print &quot;---&quot;}&apos;</span> <span class="token builtin class-name">test</span>
</code></pre>
</li>
</ul>
<h1 id="&#x9009;&#x9879;"><a name="&#x9009;&#x9879;" class="anchor-navigation-ex-anchor" href="#&#x9009;&#x9879;"><i class="fa fa-link" aria-hidden="true"></i></a>9. &#x9009;&#x9879;</h1>
<ul>
<li><p><code>-v</code>&#x5F15;&#x5165;&#x5916;&#x90E8;&#x53D8;&#x91CF;&#xFF0C;&#x591A;&#x4E2A;&#x53D8;&#x91CF;&#x4E4B;&#x95F4;&#x8981;&#x591A;&#x6B21;&#x4F7F;&#x7528;<code>-v</code>&#x53C2;&#x6570;</p>
<ul>
<li><pre class="language-"><code class="lang-bash"><span class="token assign-left variable">var1</span><span class="token operator">=</span><span class="token string">&quot;hello world&quot;</span>
<span class="token assign-left variable">var2</span><span class="token operator">=</span><span class="token number">123</span>
<span class="token function">awk</span> -v <span class="token assign-left variable">var1</span><span class="token operator">=</span><span class="token string">&quot;<span class="token variable">$var1</span>&quot;</span> -v <span class="token assign-left variable">var2</span><span class="token operator">=</span><span class="token variable">$var2</span> <span class="token string">&apos;BEGIN{print var1 var2}&apos;</span>
</code></pre>
</li>
</ul>
</li>
<li><p><code>-f</code>&#x5F15;&#x5165;&#x5916;&#x90E8;&#x542B;&#x6709;<code>awk</code>&#x7684;&#x547D;&#x4EE4;&#x6587;&#x4EF6;</p>
</li>
<li><p><code>-F</code>&#x6307;&#x5B9A;&#x6587;&#x4EF6;&#x5206;&#x9694;&#x7B26;</p>
</li>
</ul>
<h1 id="&#x5176;&#x4ED6;"><a name="&#x5176;&#x4ED6;" class="anchor-navigation-ex-anchor" href="#&#x5176;&#x4ED6;"><i class="fa fa-link" aria-hidden="true"></i></a>10. &#x5176;&#x4ED6;</h1>
<ul>
<li>&#x4F7F;&#x7528;<code>print</code>&#x6253;&#x5370;&#x591A;&#x4E2A;&#x53D8;&#x91CF;&#x65F6;&#xFF0C;&#x4E2D;&#x95F4;&#x4F7F;&#x7528;&#x9017;&#x53F7;&#x548C;&#x7A7A;&#x683C;&#x5206;&#x5F00;&#x4E0D;&#x540C;&#xFF0C;&#x524D;&#x8005;&#x4F1A;&#x81EA;&#x52A8;&#x5C06;output&#x52A0;&#x4E0A;&#x7A7A;&#x683C;&#xFF0C;&#x540E;&#x8005;&#x4E0D;&#x4F1A;</li>
</ul>
<h1 id="&#x4F8B;&#x5B50;"><a name="&#x4F8B;&#x5B50;" class="anchor-navigation-ex-anchor" href="#&#x4F8B;&#x5B50;"><i class="fa fa-link" aria-hidden="true"></i></a>11. &#x4F8B;&#x5B50;</h1>
<ul>
<li><pre class="language-"><code class="lang-bash"><span class="token function">awk</span> <span class="token string">&apos;{print NR,<span class="token variable">$0</span>}&apos;</span> <span class="token builtin class-name">test</span>            <span class="token comment"># &#x6253;&#x5370;&#x6587;&#x4EF6;&#x884C;&#x53F7;</span>
 <span class="token function">awk</span> <span class="token string">&apos;/9/{print <span class="token variable">$0</span>}&apos;</span> <span class="token builtin class-name">test</span>             <span class="token comment"># &#x6A21;&#x5F0F;&#x5339;&#x914D;</span>
  <span class="token function">awk</span> <span class="token string">&apos;{print &quot;&apos;</span><span class="token punctuation">\</span><span class="token string">&apos;&apos;</span><span class="token string">&quot;<span class="token variable">$0</span>&quot;</span><span class="token string">&apos;\&apos;&apos;</span><span class="token string">&quot;}&apos; test            # &#x5728;&#x6BCF;&#x4E00;&#x884C;&#x7684;&#x884C;&#x9996;&#x548C;&#x884C;&#x5C3E;&#x6DFB;&#x52A0;&#x5355;&#x5F15;&#x53F7;
awk &apos;(<span class="token variable">$2</span> &gt;=9000){print <span class="token variable">$1</span>, &quot;</span>high<span class="token string">&quot;}&apos; test
cat del2 | awk -F &apos;len:&apos; &apos;BEGIN {sum=0} {sum += <span class="token variable">$2</span>} END {print sum}&apos; 
awk &apos;END{print NR}&apos; filename            # &#x6253;&#x5370;&#x603B;&#x6587;&#x4EF6;&#x884C;&#x6570;
awk -F: &apos;BEGIN{print &quot;</span>username<span class="token string">&quot;,&quot;</span>bash_type<span class="token string">&quot;} {print <span class="token variable">$1</span>,<span class="token variable">$NF</span>}[9/9]
print &quot;</span><span class="token operator">==</span><span class="token operator">=</span>END<span class="token operator">==</span><span class="token operator">=</span>&quot;<span class="token punctuation">}</span><span class="token string">&apos; passwd

 cat test | awk -F &apos;</span>/+<span class="token string">&apos; &apos;</span><span class="token punctuation">{</span>print <span class="token variable">$2</span><span class="token punctuation">}</span><span class="token string">&apos; | sort | uniq -c               # &#x7EDF;&#x8BA1;&#x91CD;&#x590D;&#x5185;&#x5BB9;&#x51FA;&#x73B0;&#x7684;&#x6B21;&#x6570;
 cat test | awk -F &apos;</span>/+<span class="token string">&apos; &apos;</span><span class="token punctuation">{</span>h<span class="token punctuation">[</span><span class="token variable">$2</span><span class="token punctuation">]</span>++<span class="token punctuation">}</span> END<span class="token punctuation">{</span>for <span class="token punctuation">(</span>i <span class="token keyword">in</span> h<span class="token punctuation">)</span> print i,h<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token punctuation">}</span> &apos;     <span class="token comment"># &#x65B9;&#x6CD5;&#x4E8C;</span>
</code></pre>
</li>
<li></li>
</ul>
<h1 id="&#x53C2;&#x8003;&#x94FE;&#x63A5;"><a name="&#x53C2;&#x8003;&#x94FE;&#x63A5;" class="anchor-navigation-ex-anchor" href="#&#x53C2;&#x8003;&#x94FE;&#x63A5;"><i class="fa fa-link" aria-hidden="true"></i></a>12. &#x53C2;&#x8003;&#x94FE;&#x63A5;</h1>
<ul>
<li><a href="https://gregable.com/2010/09/why-you-should-know-just-little-awk.html" target="_blank">An Awk tutorial by Example</a>, Greg Grothaus</li>
<li><a href="https://likegeeks.com/awk-command/" target="_blank">30 Examples for Awk Command in Text Processing</a>, Mokhtar Ebrahim </li>
</ul>
<footer class="page-footer"><span class="copyright">Copyright &#xA9; AGou 2020 all right reserved&#xFF0C;powered by Gitbook</span><span class="footer-modification">&#x8BE5;&#x6587;&#x4EF6;&#x4FEE;&#x8BA2;&#x65F6;&#x95F4;&#xFF1A;
2020-03-02 20:42:24
</span></footer>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="Linux_shell.html" class="navigation navigation-prev " aria-label="Previous page: Linux Shell">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="OpenSSL、PKI搭建、算法.html" class="navigation navigation-next " aria-label="Next page: OpenSSL、PKI搭建">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"shell_awk","level":"1.4.14","depth":2,"next":{"title":"OpenSSL、PKI搭建","level":"1.4.15","depth":2,"path":"Linux/OpenSSL、PKI搭建、算法.md","ref":"Linux/OpenSSL、PKI搭建、算法.md","articles":[]},"previous":{"title":"Linux Shell","level":"1.4.13","depth":2,"path":"Linux/Linux_shell.md","ref":"Linux/Linux_shell.md","articles":[]},"dir":"ltr"},"config":{"plugins":["github@^2.0.0","edit-link@^2.0.2","anchors@^0.7.1","include-codeblock@^3.0.2","tbfed-pagefooter@^0.0.1","expandable-chapters-small@^0.1.7","anchor-navigation-ex@0.1.8","prism","-highlight","insert-logo","-lunr","-search","search-pro","splitter","lightbox","github-buttons","-sharing","sharing-plus","donate","code","-klipse","livereload"],"root":".","styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"tbfed-pagefooter":{"copyright":"Copyright © AGou 2020","modify_label":"该文件修订时间：","modify_format":"YYYY-MM-DD HH:mm:ss"},"prism":{"css":["prismjs/themes/prism-tomorrow.css"]},"github":{"url":"https://github.com/AGou-ops"},"livereload":{},"splitter":{},"search-pro":{},"sharing-plus":{"qq":false,"all":["facebook","google","twitter","instapaper","linkedin","pocket","stumbleupon"],"douban":false,"facebook":true,"weibo":false,"instapaper":false,"whatsapp":false,"hatenaBookmark":false,"twitter":true,"messenger":false,"line":false,"vk":false,"pocket":true,"google":false,"viber":false,"stumbleupon":false,"qzone":false,"linkedin":false},"code":{"copyButtons":true},"donate":{"alipay":"https://agou-ops.github.io/images/alipay.png","alipayText":"支付宝打赏","button":"打赏","title":"","wechat":"https://agou-ops.github.io/images/wechatpay.png","wechatText":"微信打赏"},"fontsettings":{"theme":"white","family":"sans","size":2},"anchor-navigation-ex":{"isRewritePageTitle":true,"tocLevel1Icon":"fa fa-hand-o-right","tocLevel2Icon":"fa fa-hand-o-right","tocLevel3Icon":"fa fa-hand-o-right"},"lightbox":{"jquery":true,"sameUuid":false},"github-buttons":{"repo":"AGou-ops/myStudyNote","types":["star","watch","fork"],"size":"small"},"expandable-chapters-small":{},"include-codeblock":{"check":false,"edit":true,"fixlang":false,"lang":"","template":"ace","theme":"chrome","unindent":true},"sharing":{"qq":true,"all":["douban","facebook","google","hatenaBookmark","instapaper","linkedin","twitter","weibo","messenger","qq","qzone","viber","vk","weibo","pocket","stumbleupon","whatsapp"],"douban":false,"facebook":false,"weibo":true,"instapaper":false,"whatsapp":false,"hatenaBookmark":false,"twitter":false,"messenger":false,"line":false,"vk":false,"pocket":false,"google":false,"viber":false,"stumbleupon":false,"qzone":true,"linkedin":false},"edit-link":{"label":"Edit This Page","base":"https://github.com/AGou-ops/myStudyNote"},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":true},"anchors":{},"insert-logo":{"style":"background: none; max-height: 50px; min-height: 50px","url":"https://s2.ax1x.com/2019/12/10/QBD0xO.jpg"}},"theme":"default","author":"AGou","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"AGou's StudyNote","language":"zh-hans","output.name":"site","links":{"sidebar":{"◆点击进入我的个人博客":"http://agou-ops.github.io"}},"gitbook":"3.2.3","description":"岂能尽如人意，但求无愧我心。"},"file":{"path":"Linux/shell_awk.md","mtime":"2020-03-02T12:42:24.292Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-03-02T12:42:32.383Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-github/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-edit-link/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-insert-logo/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-pro/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lightbox/js/lightbox.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-github-buttons/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing-plus/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-donate/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-code/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

